//
//  VisitTableViewController.swift
//  weibo
//
//  Created by yellow on 15/10/15.
//  Copyright © 2015年 yellow. All rights reserved.
//

import UIKit

class VisitTableViewController: UITableViewController {
    
 /// 通过这个属性来判断是否展现访客视图
    var isLogin:Bool{
        return UserAccountViewModel.sharedViewModel.isLoginUser
    }
 /// 访客视图
    var myVisiterView:VisiterView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
//        tableView.separatorStyle = UITableViewCellSeparatorStyle.None
    }
    
    override func loadView() {
        isLogin ? super.loadView() : bulidVisiterView()
        
    }
    
    private func bulidVisiterView(){
        myVisiterView = VisiterView()
        myVisiterView?.delegate = self
        view = myVisiterView
        addNavgationBarItem()
    }
}


// MARK: - 界面设置
extension VisitTableViewController{

    //添加访客视图中左右两边的NavgationBarItem
    private func addNavgationBarItem(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visiterViewDidClickRegisterBtn")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "visiterViewDidClickLoginBtn")
    }
}


// MARK: - VisiterViewProtocol,点击注册按钮和登录按钮的代理事件
extension VisitTableViewController:VisiterViewProtocol{
    
    func visiterViewDidClickRegisterBtn() {
        print("register")
    }
    
    func visiterViewDidClickLoginBtn() {
        
        presentViewController(UINavigationController(rootViewController: OAuthViewController()), animated: true, completion: nil)
        print("login")
    }

}